<template>
	<view class="home">
		<view class="search-box">
			<search @search="gotoSearch"></search>
		</view>
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" circular>
			<swiper-item v-for="(item,i) in swiperList" :key="i">
				<!-- 给页面详情（分包）设置跳转，且传递所点击页面的参数 -->
				<navigator class="swiper-item" :url="'/subpkg/goods_detail/goods_detail?goods_id='+ item.goods_id ">
					<image :src="item.image_src"></image>
				</navigator>
			</swiper-item>
		</swiper>
		<view class="navi">
			<view class="" v-for="(item,i) in naviList" :key="i" @click="navClickHandler(item)">
				<image :src="item.image_src" class="navi-img"></image>
			</view>
		</view>
		<view class="floor-list">
			<view class="floor-item" v-for="(item,i) in floorList" :key="i">
				<!-- 标题图片 -->
				<image :src="item.floor_title.image_src" mode="" class="floor-title"></image>				
				<view class="floor-image-box">
					<!-- 左侧大图片 -->
					<navigator class="floor-left-image" :url="item.product_list[0].url">
						<image :src="item.product_list[0].image_src" :style="{width:item.product_list[0].image_width + 'rpx'}" mode="widthFix"></image>
					</navigator>
					<view class="floor-right-image">
						<navigator class="floor-right-item" v-for="(item2,i2) in item.product_list" :key="i2" v-if="i2 !== 0" :url="item2.url">
							<image :src="item2.image_src" :style="{width:item2.image_width + 'rpx'}" mode="widthFix" ></image>
						</navigator>
					</view>
				</view>
			</view>
		</view>
		
	</view>
</template>

<script>
	import badgeMix from '@/mixins/tabbar_badge.js'
	export default {
		mixins:[badgeMix],
		data() {
			return {
				swiperList:[],
				naviList:[],
				floorList:[]
			};
		},
		onLoad(){
			this.getSwiperList()
			this.getNaviList()
			this.getFloorList()
		},
		methods:{
			navClickHandler(item){
				if(item.name === '分类'){
					uni.switchTab({
						url:"/pages/cate/cate"
					})
				}
			},
			gotoSearch(){
				uni.navigateTo({
					url:'/subpkg/goods_search/goods_search'
				})
			},
			
			
			async getSwiperList(){
				 const {data:res} = await uni.$http.get('/api/public/v1/home/swiperdata')
				 // 对请求失败做判断
				 if (res.meta.status!==200) return uni.$showMsg()
				 // 把请求回来对结果赋给swiperList
				 this.swiperList = res.message

			},
			async getNaviList(){
				 const {data:res} = await uni.$http.get('/api/public/v1/home/catitems')
				 // 对请求失败做判断
				 if (res.meta.status!==200) return uni.$showMsg()
				 this.naviList = res.message

			},
			async getFloorList(){
				 const {data:res} = await uni.$http.get('/api/public/v1/home/floordata')
				 // 对请求失败做判断
				 if (res.meta.status!==200) return uni.$showMsg()
				 res.message.forEach(floor => {
					 floor.product_list.forEach(prod => {
						 prod.url = '/subpkg/goods_list/goods_list?' + prod.navigator_url.split('?')[1]
					 })
				 })
				 this.floorList = res.message

			},
		
		}
	}
</script>

<style lang="scss">
	.home{
		margin-top: 0;
	}
	swiper{
		height: 330rpx;
		.swiper-item,
		image {
			width: 100%;
			height: 100%;
		}
	}
	
	.navi{
		display: flex;
		justify-content: space-around;
		margin: 15px 0;
		.navi-img{
			width: 128rpx;
			height: 140rpx;
		}
	}
	.floor-title{
		width: 100%;
		height: 60rpx;
	}
	.floor-right-image{
		display: flex;
		flex-wrap: wrap;
		justify-content: space-around;
	}
	.floor-image-box{
		display: flex;
		padding-left: 10rpx;
	}
	.search-box{
		position: sticky;
		top: 0;
		z-index: 999;
	}
</style>
